<?php

/**
 * This is the model class for table "tbl_medicine".
 *
 * The followings are the available columns in table 'tbl_medicine':
 * @property string $pk_medicine_id
 * @property string $fk_medicine_usage_id
 * @property integer $status
 * @property integer $category
 * @property string $chinese_name
 * @property string $common_name
 * @property string $characters
 * @property string $specification
 * @property string $dosage
 * @property string $unit
 * @property string $efficacy
 * @property string $taboo
 * @property string $usage
 * @property string $pharmaco
 * @property string $sideEffect
 * @property string $notes
 * @property string $interaction
 * @property string $attribute
 * @property string $brand
 * @property string $manufacturer
 * @property string $create_time
 * @property string $update_time
 */
class TblMedicine extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_medicine';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('pk_medicine_id, category, chinese_name, create_time, update_time', 'required'),
			array('status, category', 'numerical', 'integerOnly'=>true),
			array('pk_medicine_id, fk_medicine_usage_id', 'length', 'max'=>20),
			array('chinese_name, common_name, specification, brand', 'length', 'max'=>200),
			array('characters, efficacy', 'length', 'max'=>500),
			array('dosage, unit', 'length', 'max'=>50),
			array('taboo, usage, pharmaco, sideEffect, notes, interaction', 'length', 'max'=>45),
			array('attribute', 'length', 'max'=>100),
			array('manufacturer', 'length', 'max'=>300),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('pk_medicine_id, fk_medicine_usage_id, status, category, chinese_name, common_name, characters, specification, dosage, unit, efficacy, taboo, usage, pharmaco, sideEffect, notes, interaction, attribute, brand, manufacturer, create_time, update_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'pk_medicine_id' => 'Pk Medicine',
			'fk_medicine_usage_id' => 'Fk Medicine Usage',
			'status' => 'Status',
			'category' => 'Category',
			'chinese_name' => 'Chinese Name',
			'common_name' => 'Common Name',
			'characters' => 'Characters',
			'specification' => 'Specification',
			'dosage' => 'Dosage',
			'unit' => 'Unit',
			'efficacy' => 'Efficacy',
			'taboo' => 'Taboo',
			'usage' => 'Usage',
			'pharmaco' => 'Pharmaco',
			'sideEffect' => 'Side Effect',
			'notes' => 'Notes',
			'interaction' => 'Interaction',
			'attribute' => 'Attribute',
			'brand' => 'Brand',
			'manufacturer' => 'Manufacturer',
			'create_time' => 'Create Time',
			'update_time' => 'Update Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('pk_medicine_id',$this->pk_medicine_id,true);
		$criteria->compare('fk_medicine_usage_id',$this->fk_medicine_usage_id,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('category',$this->category);
		$criteria->compare('chinese_name',$this->chinese_name,true);
		$criteria->compare('common_name',$this->common_name,true);
		$criteria->compare('characters',$this->characters,true);
		$criteria->compare('specification',$this->specification,true);
		$criteria->compare('dosage',$this->dosage,true);
		$criteria->compare('unit',$this->unit,true);
		$criteria->compare('efficacy',$this->efficacy,true);
		$criteria->compare('taboo',$this->taboo,true);
		$criteria->compare('usage',$this->usage,true);
		$criteria->compare('pharmaco',$this->pharmaco,true);
		$criteria->compare('sideEffect',$this->sideEffect,true);
		$criteria->compare('notes',$this->notes,true);
		$criteria->compare('interaction',$this->interaction,true);
		$criteria->compare('attribute',$this->attribute,true);
		$criteria->compare('brand',$this->brand,true);
		$criteria->compare('manufacturer',$this->manufacturer,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('update_time',$this->update_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return TblMedicine the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
